/**
 * 
 */
package gwt.simulation.client;

import gwt.simulation.client.GUIParameters.AlgorithmType;
import gwt.simulation.client.GUIParameters.ModulationType;
import gwt.simulation.client.GUIParameters.SimulationType;
import gwt.simulation.client.slider.RangeSlider;
import gwt.simulation.client.slider.Slider;
import gwt.simulation.client.slider.SliderEvent;
import gwt.simulation.client.slider.SliderListener;

import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.DoubleBox;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;

public class GUIMaker implements SliderListener {

	private int blockLengthValue;
    private	int codeRateValue;
    private Label LabelSimulation = new Label("Simulation Type:\r\n");
	private Label LabelBlockLength = new Label("Block Length:");
	private Label LabelCodeRate = new Label("Code Rate:");
	private Label LabelModulation = new Label("Modulation:");
	private RootPanel rootPanel = RootPanel.get();
	private Label LabelAlgorithm = new Label("Algorithm:");
	@SuppressWarnings("deprecation")
	private DisclosurePanel disclosurePanel = new DisclosurePanel("Advanced", true);
	private ListBox DropDownModulation = new ListBox();
	private ListBox DropDownSimulationType = new ListBox();
	private ListBox DropDownAlgorithm = new ListBox();
	private IntegerBox boxBlockLength1 = new IntegerBox();
	private DoubleBox boxCodeRate1 = new DoubleBox();
	private RangeSlider rangeSliderCodeRate;
	private RangeSlider rangeSliderBlockLength;
	private IntegerBox boxBlockLength2 = new IntegerBox();
	private DoubleBox boxCodeRate2 = new DoubleBox();
	private Button sendButton = new Button("Send");
	
	
	
	/**
	 * @return the blockLengthValue
	 */
	protected double getBlockLengthValue() {
		return blockLengthValue;
	}


	/**
	 * @param blockLengthValue the blockLengthValue to set
	 */
	protected void setBlockLengthValue(int blockLengthValue) {
		this.blockLengthValue = blockLengthValue;
	}


	/**
	 * @return the codeRateValue
	 */
	protected double getCodeRateValue() {
		return codeRateValue;
	}


	/**
	 * @param codeRateValue the codeRateValue to set
	 */
	protected void setCodeRateValue(int codeRateValue) {
		this.codeRateValue = codeRateValue;
	}


	/**
	 * @return the labelSimulation
	 */
	protected Label getLabelSimulation() {
		return LabelSimulation;
	}


	/**
	 * @param labelSimulation the labelSimulation to set
	 */
	protected void setLabelSimulation(Label labelSimulation) {
		LabelSimulation = labelSimulation;
	}


	/**
	 * @return the labelBlockLength
	 */
	protected Label getLabelBlockLength() {
		return LabelBlockLength;
	}


	/**
	 * @param labelBlockLength the labelBlockLength to set
	 */
	protected void setLabelBlockLength(Label labelBlockLength) {
		LabelBlockLength = labelBlockLength;
	}


	/**
	 * @return the labelCodeRate
	 */
	protected Label getLabelCodeRate() {
		return LabelCodeRate;
	}


	/**
	 * @param labelCodeRate the labelCodeRate to set
	 */
	protected void setLabelCodeRate(Label labelCodeRate) {
		LabelCodeRate = labelCodeRate;
	}


	/**
	 * @return the labelModulation
	 */
	protected Label getLabelModulation() {
		return LabelModulation;
	}


	/**
	 * @param labelModulation the labelModulation to set
	 */
	protected void setLabelModulation(Label labelModulation) {
		LabelModulation = labelModulation;
	}


	/**
	 * @return the labelAlgorithm
	 */
	protected Label getLabelAlgorithm() {
		return LabelAlgorithm;
	}


	/**
	 * @param labelAlgorithm the labelAlgorithm to set
	 */
	protected void setLabelAlgorithm(Label labelAlgorithm) {
		LabelAlgorithm = labelAlgorithm;
	}


	/**
	 * @return the disclosurePanel
	 */
	protected DisclosurePanel getDisclosurePanel() {
		return disclosurePanel;
	}


	/**
	 * @param disclosurePanel the disclosurePanel to set
	 */
	protected void setDisclosurePanel(DisclosurePanel disclosurePanel) {
		this.disclosurePanel = disclosurePanel;
	}


	/**
	 * @return the dropDownModulation
	 */
	protected ListBox getDropDownModulation() {
		return DropDownModulation;
	}


	/**
	 * @param dropDownModulation the dropDownModulation to set
	 */
	protected void setDropDownModulation(ListBox dropDownModulation) {
		DropDownModulation = dropDownModulation;
	}


	/**
	 * @return the dropDownSimulationType
	 */
	protected ListBox getDropDownSimulationType() {
		return DropDownSimulationType;
	}


	/**
	 * @param dropDownSimulationType the dropDownSimulationType to set
	 */
	protected void setDropDownSimulationType(ListBox dropDownSimulationType) {
		DropDownSimulationType = dropDownSimulationType;
	}


	/**
	 * @return the dropDownAlgorithm
	 */
	protected ListBox getDropDownAlgorithm() {
		return DropDownAlgorithm;
	}


	/**
	 * @param dropDownAlgorithm the dropDownAlgorithm to set
	 */
	protected void setDropDownAlgorithm(ListBox dropDownAlgorithm) {
		DropDownAlgorithm = dropDownAlgorithm;
	}


	/**
	 * @return the rangeSliderCodeRate
	 */
	protected RangeSlider getRangeSliderCodeRate() {
		return rangeSliderCodeRate;
	}


	/**
	 * @param rangeSliderCodeRate the rangeSliderCodeRate to set
	 */
	protected void setRangeSliderCodeRate(RangeSlider rangeSliderCodeRate) {
		this.rangeSliderCodeRate = rangeSliderCodeRate;
	}


	/**
	 * @return the rangeSliderBlockLength
	 */
	protected RangeSlider getRangeSliderBlockLength() {
		return rangeSliderBlockLength;
	}


	/**
	 * @param rangeSliderBlockLength the rangeSliderBlockLength to set
	 */
	protected void setRangeSliderBlockLength(RangeSlider rangeSliderBlockLength) {
		this.rangeSliderBlockLength = rangeSliderBlockLength;
	}


	/**
	 * @return the boxBlockLength2
	 */
	protected IntegerBox getBoxBlockLength2() {
		return boxBlockLength2;
	}


	/**
	 * @param boxBlockLength2 the boxBlockLength2 to set
	 */
	protected void setBoxBlockLength2(IntegerBox boxBlockLength2) {
		this.boxBlockLength2 = boxBlockLength2;
	}


	/**
	 * @return the boxCodeRate2
	 */
	protected DoubleBox getBoxCodeRate2() {
		return boxCodeRate2;
	}


	/**
	 * @param boxCodeRate2 the boxCodeRate2 to set
	 */
	protected void setBoxCodeRate2(DoubleBox boxCodeRate2) {
		this.boxCodeRate2 = boxCodeRate2;
	}


	/**
	 * @return the boxBlockLength1
	 */
	protected IntegerBox getBoxBlockLength1() {
		return boxBlockLength1;
	}


	/**
	 * @return the boxCodeRate1
	 */
	protected DoubleBox getBoxCodeRate1() {
		return boxCodeRate1;
	}


	
	/**
	 * this method creates all labels, menus and buttons and set the size of them
	 * @wbp.parser.entryPoint
	 */
	protected void createInterface(){
		
		rootPanel.add(LabelSimulation, 60, 60);
		rootPanel.add(LabelBlockLength, 60, 158);
		rootPanel.add(LabelCodeRate, 60, 224);		
		rootPanel.add(LabelModulation, 60, 288);		
		rootPanel.add(LabelAlgorithm, 60, 402);
		rootPanel.add(DropDownModulation, 340, 293);
		rootPanel.add(DropDownSimulationType, 340, 62);
		rootPanel.add(DropDownAlgorithm, 340, 404);
		rootPanel.add(disclosurePanel, 60, 511);
        RootPanel.get("rangeContainer").add(rangeSliderBlockLength, 352, 170);
        rootPanel.add(rangeSliderCodeRate, 360, 216);
		rootPanel.add(boxBlockLength1, 304, 167);
		rootPanel.add(boxBlockLength2, 619, 165);
		rootPanel.add(boxCodeRate2, 619, 221);
		rootPanel.add(boxCodeRate1, 304, 221);
		rootPanel.add(sendButton, 602, 60);
		
		DropDownModulation.setStyleName("DropDownStyle");
		DropDownSimulationType.setStyleName("DropDownStyle");
		DropDownAlgorithm.setStyleName("DropDownStyle");
		
		LabelBlockLength.setSize("176px", "29px");
		LabelCodeRate.setSize("176px", "29px");
		LabelModulation.setSize("176px", "29px");
		LabelAlgorithm.setSize("176px", "29px");
		DropDownModulation.setSize("139px", "20px");		
		DropDownSimulationType.setSize("139px", "20px");
		DropDownAlgorithm.setSize("139px", "20px");
		disclosurePanel.setSize("630px", "198px");
		boxBlockLength1.setSize("27px", "16px");
		boxBlockLength2.setSize("27px", "16px");
		boxCodeRate1.setSize("27px", "16px");
		boxCodeRate2.setSize("27px", "16px");
        rangeSliderBlockLength.setSize("241px", "11px");		
        rangeSliderCodeRate.setSize("241px", "11px");
		
		sendButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
			}
		});

	}
	
	
	/**
	 * @return the sendButton
	 */
	protected Button getSendButton() {
		return sendButton;
	}


	/**
	 * @param sendButton the sendButton to set
	 */
	protected void setSendButton(Button sendButton) {
		this.sendButton = sendButton;
	}


	/**
	 * this method starts all search parameters which were declared in SearchParameter class
	 * 
	 */
	protected void startParameters(){
		
		GUIParameters parameters = new GUIParameters();
		    	
		for(SimulationType simulation : SimulationType.values()) {
			getDropDownSimulationType().addItem(simulation.toString());
		}

		for(ModulationType modulation : ModulationType.values()) {
			getDropDownModulation().addItem(modulation.toString());
		}
		
		for(AlgorithmType algorithm : AlgorithmType.values()) {
			getDropDownModulation().addItem(algorithm.toString());
		}
		
		rangeSliderCodeRate = new RangeSlider("range2", parameters.getMinCodeRate(), parameters.getMaxCodeRate(), 25, 40);
    	rangeSliderBlockLength = new RangeSlider("range", parameters.getMinBlocklength(), parameters.getMaxBlocklength(), 25, 40);
		rangeSliderCodeRate.addListener(this);
        rangeSliderBlockLength.addListener(this);

	}
	
	
   @Override
   /*
    * (non-Javadoc)
    * @see gwt.simulation.client.widget.slider.SliderListener#onChange(gwt.simulation.client.widget.slider.SliderEvent)
    */
    public void onChange(SliderEvent e)
    {
        //We don't need to do anything, because everything is done in onSlide in this example
    }

    @Override
    /*
     * (non-Javadoc)
     * @see gwt.simulation.client.widget.slider.SliderListener#onSlide(gwt.simulation.client.widget.slider.SliderEvent)
     */
    public boolean onSlide(SliderEvent e)
    {
    	Slider source = e.getSource();
        if (source == rangeSliderBlockLength){
        	boxBlockLength2.setValue(e.getValues()[1]);
        	boxBlockLength1.setValue(e.getValues()[0]);
        } else if (source == rangeSliderCodeRate){
        	boxCodeRate2.setValue((double) e.getValues()[1]);
        	boxCodeRate1.setValue((double) e.getValues()[0]);
        }
        
        return true;
    }

    @Override
    /*
     * (non-Javadoc)
     * @see gwt.simulation.client.widget.slider.SliderListener#onStart(gwt.simulation.client.widget.slider.SliderEvent)
     */
    public void onStart(SliderEvent e)
    {
        // We are not going to do anything onStart
    }

    @Override
    /*
     * (non-Javadoc)
     * @see gwt.simulation.client.widget.slider.SliderListener#onStop(gwt.simulation.client.widget.slider.SliderEvent)
     */
    public void onStop(SliderEvent e)
    {
        // We are not going to do anything onStop        
    }
}
